package com.mt.course.service.impl;

import java.util.List;
import java.util.Map;


import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.mt.common.PagerInfo;
import com.mt.common.ServiceResult;
import com.mt.common.constants.BaseErrorConstants;
import com.mt.course.api.service.ICourseCollectService;
import com.mt.course.entity.CourseCollectEntity;
import com.mt.course.service.model.CourseCollectServiceModel;
import org.springframework.stereotype.Service;

@Service
public class CourseCollectServiceImpl implements ICourseCollectService {

    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(CourseCollectServiceImpl.class);

    @Autowired
    private CourseCollectServiceModel courseCollectServiceModel;

    public ServiceResult<CourseCollectEntity> findInfo(Map<String, Object> params) {
        ServiceResult<CourseCollectEntity> result = null;
        try {
            result = courseCollectServiceModel.selectInfo(params);
        } catch (Exception e) {
            LOGGER.error("[CourseCollectServiceImpl][findInfo]：query findInfo occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "查询详情错误");
        }
        return result;
    }

    public ServiceResult<List<CourseCollectEntity>> findList(Map<String, Object> params, PagerInfo<?> pagerInfo) {
        ServiceResult<List<CourseCollectEntity>> result = new ServiceResult<List<CourseCollectEntity>>();
        try {
            result = courseCollectServiceModel.selectList(params, pagerInfo);
        } catch (Exception e) {
            LOGGER.error("[CourseCollectServiceImpl][findList]：query findList occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "查询列表错误");
        }

        return result;
    }

    public ServiceResult<Integer> findCount(Map<String, Object> params) {
        ServiceResult<Integer> result = null;
        try {
            result = courseCollectServiceModel.selectCount(params);
        } catch (Exception e) {
            LOGGER.error("[CourseCollectServiceImpl][findCount]：query findInfo occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "查询详情错误");
        }
        return result;
    }

    public ServiceResult<Integer> doInsert(CourseCollectEntity courseCollectEntity) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = courseCollectServiceModel.insert(courseCollectEntity);
        } catch (Exception e) {
            LOGGER.error("[CourseCollectServiceImpl][doInsert]：query doInsert occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "创建信息错误");
        }
        return result;
    }

    public ServiceResult<Integer> doDeleteById(Integer collectId) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = courseCollectServiceModel.deleteByPrimaryKey(collectId);
        } catch (Exception e) {
            LOGGER.error("[CourseCollectServiceImpl][doDeleteById]：query doDeleteById occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "删除信息错误");
        }
        return result;
    }

    public ServiceResult<Integer> doDeleteByCustomer(Map<String, Object> params) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = courseCollectServiceModel.deleteByCustomer(params);
        } catch (Exception e) {
            LOGGER.error("[CourseCollectServiceImpl][doDeleteByCustomer]：query doDeleteById occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "删除信息错误");
        }
        return result;
    }

    public ServiceResult<Integer> doUpdate(CourseCollectEntity courseCollectEntity) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = courseCollectServiceModel.updateByPrimaryKeySelective(courseCollectEntity);
        } catch (Exception e) {
            LOGGER.error("[CourseCollectServiceImpl][doUpdate]：query doUpdate occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "更新信息错误.");
        }
        return result;
    }

}
